<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<form action="{url:/text/add_to}" method="post">
		<center>
			<table>
				<tr>
					<td>用户名</td>
					<td><input type="text" name="name"></td>
				</tr>
				<tr>
					<td>地址</td>
					<td><input type="text" name="url" id="url"><div style="width:500px;height:300px;" id="map"></div></td>

				</tr>

				<tr>
					<td>
						<input type="button" value="酒店" id="each">
						<input type="button" value="饭店" id="fan">
					</td>
				</tr>
			</table>
		</center>	
	</form>
</body>
</html>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=HNmzxMNkSOx0fFcLekUh00s0nYE3VKx2"></script>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
	$(document).on("blur","#url",function(){
		var name=$(this).val();
		$.ajax({
				url:"{url:/text/town}",
				data:{name:name},
				type:"post",
				dataType:"json",
				success:function(e){
					var lng=e.lng;
					var lat=e.lat;
					var map = new BMap.Map("map");
					var point = new BMap.Point(lng,lat);
					map.centerAndZoom(point,15);
					var geoc = new BMap.Geocoder();    

					map.addEventListener("click", function(e){        
						var pt = e.point;
						geoc.getLocation(pt, function(rs){
							var addComp = rs.addressComponents;
							alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
		});        
	});
}
})
})


$(document).on("blur","#each",function(){
		var name=$("#url").val();
		$.ajax({
				url:"{url:/text/town}",
				data:{name:name},
				type:"post",
				dataType:"json",
				success:function(e){
					var lng=e.lng;
					var lat=e.lat;
					var map = new BMap.Map("map");            // 创建Map实例
	var mPoint = new BMap.Point(lng,lat);  
	map.enableScrollWheelZoom();
	map.centerAndZoom(mPoint,15);

	var circle = new BMap.Circle(mPoint,1000,{fillColor:"blue", strokeWeight: 1 ,fillOpacity: 0.3, strokeOpacity: 0.3});
    map.addOverlay(circle);
    var local =  new BMap.LocalSearch(map, {renderOptions: {map: map, autoViewport: false}});  
    local.searchNearby('酒店',mPoint,3000);     
	}
})
})

$(document).on("blur","#fan",function(){
		var name=$("#url").val();
		$.ajax({
				url:"{url:/text/town}",
				data:{name:name},
				type:"post",
				dataType:"json",
				success:function(e){
					var lng=e.lng;
					var lat=e.lat;
					var map = new BMap.Map("map");            // 创建Map实例
	var mPoint = new BMap.Point(lng,lat);  
	map.enableScrollWheelZoom();
	map.centerAndZoom(mPoint,15);

	var circle = new BMap.Circle(mPoint,1000,{fillColor:"blue", strokeWeight: 1 ,fillOpacity: 0.3, strokeOpacity: 0.3});
    map.addOverlay(circle);
    var local =  new BMap.LocalSearch(map, {renderOptions: {map: map, autoViewport: false}});  
    local.searchNearby('网吧',mPoint,3000);     
	}
})
})
map.enableScrollWheelZoom(true);
	
</script>